package main

import (
	demo "demo/kitex_gen/demo/studentservice"
	"github.com/cloudwego/kitex/pkg/rpcinfo"
	"github.com/cloudwego/kitex/server"
	"github.com/kitex-contrib/registry-nacos/registry"
	"github.com/nacos-group/nacos-sdk-go/clients"
	"github.com/nacos-group/nacos-sdk-go/common/constant"
	"github.com/nacos-group/nacos-sdk-go/vo"
	"log"
)

func main() {
	// 启动服务端后需要注册服务
	sc := []constant.ServerConfig{
		{IpAddr: "xiao666.top", Port: 443, Scheme: "https", ContextPath: "/nacos"},
	}

	cc := &constant.ClientConfig{
		NamespaceId: "service_foodplatform",
		TimeoutMs:   10000,    // 请求Nacos服务端的超时时间，默认是10000ms
		Username:    "nacos",  // Nacos服务端的API鉴权Username
		Password:    "123456", // Nacos服务端的API鉴权Password
	}

	cli, err := clients.NewNamingClient(vo.NacosClientParam{ClientConfig: cc, ServerConfigs: sc})

	svr := demo.NewServer(
		new(StudentServiceImpl),
		server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "student"}),
		server.WithRegistry(registry.NewNacosRegistry(cli)),
	)

	// 启动服务
	err = svr.Run()
	if err != nil {
		log.Println(err.Error())
	}
}
